# 闭包形式的装饰器
#


def outer_fn(fn:callable):
    def inner_fn(*args, **kwargs):
        # 执行被装饰的函数
        print("args", args)
        print("kwargs", kwargs)
        fn(*args, **kwargs)
    return inner_fn



def foo(*args, **kwargs):
    print("Function foo called with arguments:", args, kwargs) # Function foo called with arguments: (1, 2, 3, ['a', 'b']) {'key1': 'value1', 'key2': 'value2'}

# 标准模式
ot1 = outer_fn(foo)
ot1(1, 2, 3, ["a","b"], key1="value1", key2="value2")

# 语法糖模式
@outer_fn
def bar(*args, **kwargs):
    print("Function bar called with arguments:", args, kwargs) # Function bar called with arguments: (1, 2, 3) {'name': 'leslie', 'age': 18}

bar(1, 2, 3, name="leslie", age=18)